Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Calendar] Remove promise based loading in favor of loading prop #1829

Merged
merged 5 commits into from
May 28, 2020

Conversation

dmtrKovalenko
Copy link
Member

@dmtrKovalenko dmtrKovalenko commented May 25, 2020

This PR closes #1454

User facing changes

Breaking changes

  • Removed ability to return Promise from the onMonthChangeProp to render spinner in the component. From now on use loading prop to render LoadingComponent in the calendar.
  • Rename loadingIndicator to LoadingComponent

Features

  • Improve the experience of server-side data loading by exposing loading prop that will render loading placeholder while data is loading.
  • Provide new CalendarSkeleton component that can be used to achieve first-class UX experience for preloading data on month change:
    image

@vercel
Copy link

vercel bot commented May 25, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/mui-org/material-ui-pickers/qp2h2p173
✅ Preview: https://material-ui-pickers-git-feature-remove-promise-based-loading.mui-org.now.sh

@cypress
Copy link

cypress bot commented May 25, 2020



Test summary

78 0 1 0


Run details

Project material-ui-pickers
Status Passed
Commit 7e3286f
Started May 26, 2020 5:01 PM
Ended May 26, 2020 5:03 PM
Duration 01:25 💡
OS Linux Debian - 9.11
Browser Chrome 78

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

})
.then(res => res.json())
.then(({ daysToHighlight }) => {
setSelectedDays(daysToHighlight);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the component unmounts before the request resolves? I believe the set state call will warn/throw. The solution proposed in could be applied here too mui/mui-x#5 (comment)

Copy link
Member Author

@dmtrKovalenko dmtrKovalenko May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are saving abort controller. So needs to make an effect that will abort request on unmount. thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one way to solve this. I have no idea what's the best approach. I guess it's good enough, no need to look further 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, but I think that this solution has one giant pitfall – it doesn't abort the request.

Probably if we want to support IE we must not use fetch and promises at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can requests be aborted? I mean, does it change something at the network layer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually request/response model cannot be aborted, but browsers can prevent some calculations on the responses if they are aborted (like processing low-level body and CORS)

Here network log when fast switching between months with request aborts:
image

Without:
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

@dmtrKovalenko dmtrKovalenko marked this pull request as ready for review May 26, 2020 17:02
@dmtrKovalenko dmtrKovalenko merged commit c932737 into next May 28, 2020
@dmtrKovalenko dmtrKovalenko deleted the feature/remove-promise-based-loading branch May 28, 2020 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Promise based api in favor of loading prop
2 participants